package com.travelms.controller;

import com.travelms.dao.DBFind;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Scanner;

public class ForgetPassword {
    public ForgetPassword() throws SQLException, IOException {
        DBFind dbFind = new DBFind();
        try {
            while (true) {
                Scanner sc = new Scanner(System.in);
                System.out.println("输入exit退出");
                System.out.println("请输入要找回的账号:");
                String user = sc.nextLine();
                if("exit".equals(user)){
                    break;
                }

                System.out.println("请输入该账号的找回凭证");
                String key = sc.nextLine();
                if("exit".equals(key)){
                    break;
                }
                if(dbFind.isContainKey(user,key)){
                    System.out.println("找回成功");
                    System.out.println("账号:" + user);
                    System.out.println("密码:" + dbFind.getPassword(user));
                    try {
                        System.out.println("3秒后自动退出");
                        System.out.println("3");
                        Thread.sleep(1000);
                        System.out.println("2");
                        Thread.sleep(1000);
                        System.out.println("1");
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    break;
                }else {
                    System.out.println("没有该账号或凭证错误，请检查后在进行提交");
                }
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            dbFind.close();
        }
    }
}
